package test10;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class TestMain {
    public static void main(String[] args) throws IOException {

        // 接收输入
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个字符串: ");
        String str = sc.nextLine();

        // 字符流写入
        FileWriter fileWriter = new FileWriter("a.txt");
        char[] chars = str.toCharArray();
        fileWriter.write(chars);
        fileWriter.flush();

        // 字符流读取
        FileReader fileReader = new FileReader("a.txt");
        int read;
        while ((read = fileReader.read()) != -1) {
            System.out.print((char) read);
        }

        sc.close();
        fileWriter.close();
        fileReader.close();

    }
}
